#include <glib.h>

#define GLIB_BASE64_BLOCK_SIZE 16

gint main(gint argc, gchar **argv)
{
    gchar *base64_en_data = NULL;
    const guchar *ori_data = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";

    g_print("ori_data: %s \n", ori_data);
#if 1
    base64_en_data = g_base64_encode(ori_data, strlen(ori_data));
    g_print("base64 encode:%s -> %s \n", ori_data, base64_en_data);
    g_free(base64_en_data);
#endif

    /*encode by step*/
    gint processed_len = 0;
    gint output_len = 0;
    gint state = 0;
    gint save = 0;
    gboolean line_break = FALSE;

    gint ori_data_len = 0;
    gchar *en_data = NULL;

    ori_data_len = strlen(ori_data);
    en_data = g_malloc0((ori_data_len * 4));

    while (processed_len < ori_data_len)
    {
        gint block_size = MIN (GLIB_BASE64_BLOCK_SIZE, ori_data_len - processed_len);
        output_len += g_base64_encode_step (ori_data+processed_len, block_size,
            line_break, en_data+output_len, &state, &save);
        processed_len += block_size;
    }
    output_len += g_base64_encode_close (line_break, en_data + output_len, &state, &save);

    g_print("step en_data:%s \n", en_data);

    g_free(en_data);
 
    return 0;
}